package com.chinacoal.hr.levelimpl.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinacoal.hr.levelapi.entity.AttendanceAppealDetail;
import com.chinacoal.hr.levelimpl.mapper.AttendanceAppealDetailMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: YunTao.Li
 * @create: 2019-11-18 23:56
 * @description:
 **/
@Component
public class AttendanceAppealDetailDao {
    @Resource
    private AttendanceAppealDetailMapper attendanceAppealDetailMapper;

    public void insertAttendanceAppealDetail(AttendanceAppealDetail record) {
        attendanceAppealDetailMapper.insert(record);
    }

    public void updateAttendanceAPpealDetail(AttendanceAppealDetail attendanceAppealDetail) throws Throwable{
        this.attendanceAppealDetailMapper.updateById(attendanceAppealDetail);
    }

    /**
     * 根据申诉id删除此申诉下的所有申诉明细
     * @author : YunTao.Li
     * @date : 2019/11/26 2019/11/26
     * @param explainId :
     * @return : void
     */
    public void deleteAttendanceAppealDetailByExplainId(String explainId) throws Throwable {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("EXPLAIN_ID", explainId);
        attendanceAppealDetailMapper.delete(queryWrapper);
    }


    /**
     * @param explainId : 考勤申诉主表ID
     * @return : java.util.List<com.chinacoal.hr.levelimpl.entity.AttendanceAppealDetail>
     * @author : YunTao.Li
     * @date : 2019/11/26 2019/11/26
     */
    public List<AttendanceAppealDetail> getAttendanceAppealDetailListByAppealId(String explainId) throws Throwable{
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("EXPLAIN_ID", explainId);
        List<AttendanceAppealDetail> attendanceAppealDetails = null;
        try {
            attendanceAppealDetails = attendanceAppealDetailMapper.selectList(queryWrapper);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }

        return attendanceAppealDetails;
    }
}
